package com.longshihan.bei;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by longshihan on 2017/6/14.
 */

public class Test321 extends View {
    public Test321(Context context) {
        super(context);
        init();
    }


    public Test321(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public Test321(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public Test321(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int
            defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private final Path mPath = new Path();

    private void init() {


        //
        Paint paint = mPaint;
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);

        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(5);

        //一阶
        Path path = mPath;
        path.moveTo(100, 100);
        path.lineTo(400, 400);

        //二阶
        path.quadTo(600, 100, 800, 400);
        //相对的实现
        //path.rQuadTo(200,-300,400,0);

        path.moveTo(400, 800);
        //三节
        // path.cubicTo(500, 600, 700, 1000,800,800);
        path.rCubicTo(100, -200, 300, 400, 400, 0);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(mPath, mPaint);
    }
}
